/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
const path = require("path")
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};
  config.static = {
    // 静态化访问前缀,如：`http://127.0.0.1:7001/static/images/logo.png`
    prefix: '/static', 
    dir: path.join(appInfo.baseDir, 'app/public'), // `String` or `Array:[dir1, dir2, ...]` 静态化目录,可以设置多个静态化目录
    dynamic: true, // 如果当前访问的静态资源没有缓存，则缓存静态文件，和`preload`配合使用；
    preload: false,
    maxAge: 31536000, // in prod env, 0 in other envs
    buffer: true, // in prod env, false in other envs
  };

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1596762891218_4324';
  config.bodyParser ={
    jsonLimit: '100mb',
    formLimit: '100mb',
  }
  config.multipart = { 
    mode: 'file', 
    fileSize:1048576000,
    whitelist: [ '.png','.jpg','.mp3','.mp4','.m4a','.flac'],
  }

  config.security = {
    csrf: {
      enable: false,
    },
    domainWhiteList:['http://192.168.0.102:8888','http://192.168.0.102:9999']
  };
  config.cors={
    origin: ctx => ctx.get('origin'),
    credentials: true,  //允许Cook可以跨域
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS'
  };
  config.view = {
    mapping: {
      '.html': 'ejs',
    },
  };
  // add your middleware config here
  config.middleware = ['hasLogin'];
  config.sequelize = {
    dialect: 'mysql',
    host: '127.0.0.1',
    port: 3306,
    user: 'root',
    password: 'root',
    database: 'ocy',
    define: {
      freezeTableName: true//防止orm的时候表名复数化
    },
    //时区设置
    timezone: '+08:00',
  };
  config.mysql = {
    // database configuration
    client: {
      // host
      host: 'localhost',
      // port
      port: '3306',
      // username
      user: 'root',
      // password
      password: 'root',
      // database
      database: 'ocy',
    },
    // load into app, default is open
    app: true,
    // load into agent, default is close
    agent: false,
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
